﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Caching;
namespace Com.CMS263.Caches
{
    public class CacheUtil
    {

       
        /// <summary>
        /// 添加要缓存的对象
        /// </summary>
        /// <param name="obj"></param>
        public static void Add(Object obj, string key, string dpName)
        {
            CacheDependency cd = new CacheDependency(dpName);

           // CacheItemRemovedCallback remove = new CacheItemRemovedCallback(RemoveDataCallBack);
            
               System.Web.HttpRuntime.Cache.Add(key, obj, 
                   cd,
                   Cache.NoAbsoluteExpiration, 
                   Cache.NoSlidingExpiration, 
                   CacheItemPriority.Normal, 
                   null);
           

           

        }
        
        /// <summary>
        /// 通过key得到缓存的数据
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static  Object GetDataByKey(string key)
        {
            return System.Web.HttpRuntime.Cache.Get(key);
        }

        
    }
}
